package view;

import java.io.IOException;

import javax.media.MediaLocator;

import rmiClient.Client_IMPL;

public class Transmit extends Thread {
	private VideoTransmit vt;
	private Client_IMPL clientLocal;

	public Transmit(String args[], Client_IMPL clientLocal) {
		this.clientLocal = clientLocal;
		// Create a video transmit object with the specified params.
		vt = new VideoTransmit(new MediaLocator(args[0]), args[1], args[2]);
	}

	public VideoTransmit getVt() {
		return vt;
	}

	@Override
	public void run() {
		// Start the transmission
		String result = vt.start();

		// result will be non-null if there was an error. The return
		// value is a String describing the possible error. Print it.
		if (result != null) {
			System.err.println("Error : " + result);
			System.exit(0);
		}

		System.err.println("Start transmission for 60 seconds...");

		// Transmit for 60 seconds and then close the processor
		// This is a safeguard when using a capture data source
		// so that the capture device will be properly released
		// before quitting.
		// The right thing to do would be to have a GUI with a
		// "Stop" button that would call stop on VideoTransmit
		try {
			Thread.currentThread();
			Thread.sleep(60000);
		} catch (InterruptedException ie) {
		}

		// Stop the transmission
		try {
			vt.stop();
		} catch (IOException e) {
			System.err.println("could not stop properly");
		}
		System.err.println("...transmission ended.");
		MainFrame.lectureEnCours = false;
		clientLocal.setTransmitionEnCours(false);
	}

	public void setVt(VideoTransmit vt) {
		this.vt = vt;
	}
}